package com.gzmu.storage.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gzmu.storage.entity.Chest;
import com.gzmu.storage.service.AdminlogService;
import com.gzmu.storage.service.ChestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-04-16
 */
@Controller
@RequestMapping("/chest")
public class ChestController {
    @Autowired
    private ChestService chestService;
    @Autowired
    private AdminlogService adminlogService;

    @ResponseBody
    @RequestMapping("addChest")
    public Object addChest(Chest chest){
        Map map = new HashMap<>();
        Date date = new Date(  );
        chest.setCreatetime( date );
        chest.setUpdatetime( date );
        chest.setRemark( "箱门" );
        chest.setIntakecur( 0 );
//        chest.setStatus( 0 );
        boolean b = chestService.insertAndUpdate( chest );
        adminlogService.insertAdminlog("添加" + chest.getName() + "箱门");
        map.put( "code", b);
        return JSONObject.toJSON(map);
    }

    @ResponseBody
    @RequestMapping("getChest")
    public Object getChest(String id){
        Map map = new HashMap<>();
        EntityWrapper wrapper = new EntityWrapper(  );
        wrapper.eq( "cabinetid", id);
        List<Chest> chests = chestService.selectList( wrapper );
        map.put( "code", true);
        map.put( "data", chests );
        return JSONObject.toJSON(map);
    }
}

